package com.i2863.watchdog.yunpian;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.i2863.watchdog.util.HttpSessionUtils;
import org.apache.http.impl.client.CloseableHttpClient;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class SmsUtil  {
    public static final String PREFIX = "【千域互联】";

    public static final CloseableHttpClient client = HttpSessionUtils.buildHttpClient();


    public static void sendMsg(String mobis,String strMessage) throws IOException {
        final String api = "https://sms.yunpian.com/v2/sms/single_send.json";
        Map<String,String> param = new HashMap();
        param.put("apikey","1d5ce89a34493dcb43470985708ebad4");
        param.put("mobile",mobis);
        param.put("text",strMessage);
        String json =  HttpSessionUtils.httpPost(client,api,param);
        JSONObject jsonObject = JSON.parseObject(json);
        int code = jsonObject.getIntValue("code");
        String msg = jsonObject.getString("msg");
        if(code!=0){
            throw new YunpianSmsException(msg);
        }
    }

}
